Eclipse Platform
Pre-release 3.0

org.eclipse.ui.commands
Class CommandContributionItem

java.lang.Object
  extended byorg.eclipse.jface.action.ContributionItem
      extended byorg.eclipse.ui.commands.CommandContributionItem
All Implemented Interfaces:
ICommandListener, IContributionItem

public class CommandContributionItem
extends ContributionItem
implements ICommandListener

A contribution item which delegates to a command. This is a contribution item that just passes as much of the complexity as it can on to the underlying command.

This class may be instantiated; it is not intended to be subclassed.

Since:
3.0

Constructor Summary
CommandContributionItem(ICommand commandToUse)
          Creates a new contribution item from the given command.
 
Method Summary
 void commandChanged(CommandEvent e)
          Handles a change event on the command.
 boolean equals(Object o)
          Compares this command contribution item with another object.
 void fill(Composite parent)
          The CommandContributionItem implementation of this IContributionItem method creates an SWT Button for the command using the command's style.
 void fill(Menu parent, int index)
          The CommandContributionItem implementation of this IContributionItem method creates an SWT MenuItem for the action using the command's style.
 void fill(ToolBar parent, int index)
          The CommandContributionItem implementation of this IContributionItem method creates an SWT ToolItem for the command using the command's style.
 ICommand getCommand()
          Returns the command associated with this contribution item.
static boolean getUseColourIconsInToolbars()
          Returns whether color icons should be used in toolbars.
 int hashCode()
           
 boolean isDynamic()
          The command item implementation of this IContributionItem method returns true for menu items and false for everything else.
 boolean isEnabled()
          The default implementation of this IContributionItem method returns true.
protected  boolean isEnabledAllowed()
          Returns true if this item is allowed to enable, false otherwise.
 boolean isVisible()
          Whether this contribution item should be visible.
static String removeAcceleratorText(String text)
          Convenience method for removing any optional accelerator text from the given string.
static void setUseColourIconsInToolbars(boolean newValue)
          Sets whether color icons should be used in toolbars.
 void update()
          The command item implementation of this IContributionItem method calls update(null).
 void update(CommandEvent event)
          Synchronizes the UI with the given property.
 
Methods inherited from class org.eclipse.jface.action.ContributionItem
dispose, fill, getId, getParent, isDirty, isGroupMarker, isSeparator, saveWidgetState, setParent, setVisible, toString, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandContributionItem

public CommandContributionItem(ICommand commandToUse)
Creates a new contribution item from the given command. The id of the command is used as the id of the item.

Method Detail

getUseColourIconsInToolbars

public static boolean getUseColourIconsInToolbars()
Returns whether color icons should be used in toolbars.

Returns:
true if color icons should be used in toolbars; false otherwise.

removeAcceleratorText

public static String removeAcceleratorText(String text)
Convenience method for removing any optional accelerator text from the given string. The accelerator text appears at the end of the text, and is separated from the main part by a single tab character '\t'.

Parameters:
text - The text to be stripped; must not be null.
Returns:
The text sans accelerator; never null.

setUseColourIconsInToolbars

public static void setUseColourIconsInToolbars(boolean newValue)
Sets whether color icons should be used in toolbars.

Parameters:
newValue - true if color icons should be used in toolbars, false otherwise

commandChanged

public void commandChanged(CommandEvent e)
Handles a change event on the command. This performs an update of the underlying widget to reflect the change.

Specified by:
commandChanged in interface ICommandListener
Parameters:
e - The triggering event; must not be null.

equals

public boolean equals(Object o)
Compares this command contribution item with another object. Two command contribution items are equal if they refer to the equivalent command.

Parameters:
o - The object with which to compare; may be null.

fill

public void fill(Composite parent)
The CommandContributionItem implementation of this IContributionItem method creates an SWT Button for the command using the command's style. If the command's checked property has been set, the button is created and primed to the value of the checked property.

Specified by:
fill in interface IContributionItem
Overrides:
fill in class ContributionItem
Parameters:
parent - The composite parent which this contribution should place itself on; must not be null.

fill

public void fill(Menu parent,
                 int index)
The CommandContributionItem implementation of this IContributionItem method creates an SWT MenuItem for the action using the command's style. If the command's checked property has been set, a button is created and primed to the value of the checked property. If the command's menu creator property has been set, a cascading submenu is created.

Specified by:
fill in interface IContributionItem
Overrides:
fill in class ContributionItem
Parameters:
parent - The menu on which this contribution item should place itself; must not be null.
index - The index at which this contribution item should place itself. If it is a negative number, then this simply appends the item.

fill

public void fill(ToolBar parent,
                 int index)
The CommandContributionItem implementation of this IContributionItem method creates an SWT ToolItem for the command using the command's style. If the command's checked property has been set, a button is created and primed to the value of the checked property. If the command's menu creator property has been set, a drop-down tool item is created.

Specified by:
fill in interface IContributionItem
Overrides:
fill in class ContributionItem
Parameters:
parent - The tool bar on which this contribution item should place itself; must not be null.
index - The index at which this contribution item should place itself. If it is a negative number, then this simply appends the item.

getCommand

public ICommand getCommand()
Returns the command associated with this contribution item.

Returns:
The associated command; never null.

hashCode

public int hashCode()

isDynamic

public boolean isDynamic()
The command item implementation of this IContributionItem method returns true for menu items and false for everything else.

Specified by:
isDynamic in interface IContributionItem
Overrides:
isDynamic in class ContributionItem

isEnabled

public boolean isEnabled()
Description copied from class: ContributionItem
The default implementation of this IContributionItem method returns true. Subclasses may override.

Specified by:
isEnabled in interface IContributionItem
Overrides:
isEnabled in class ContributionItem

isEnabledAllowed

protected boolean isEnabledAllowed()
Returns true if this item is allowed to enable, false otherwise.

Returns:
If this item is allowed to be enabled
Since:
2.0

isVisible

public boolean isVisible()
Whether this contribution item should be visible.

Specified by:
isVisible in interface IContributionItem
Overrides:
isVisible in class ContributionItem
Returns:
true if the command is active; false otherwise.

update

public void update()
The command item implementation of this IContributionItem method calls update(null).

Specified by:
update in interface IContributionItem
Overrides:
update in class ContributionItem

update

public void update(CommandEvent event)
Synchronizes the UI with the given property.

Parameters:
event - The event triggering the update (which specifies how much of the command changed). If null, then everything is updated.

Eclipse Platform
Pre-release 3.0

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.